home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2.sit
/
Raven 1.2
/
Source
/
Foundation
/
OS
/
ZPatch.h
< prev
next >
Wrap
Text File
|
1997-06-18
|
3KB
|
104 lines
/*
* File: ZPatch.h
* Summary: Classes to help with patching traps.
* Written by: Jesse Jones
*
* Copyright ゥ 1996 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Classes: TTrapPatch - Base class for patching traps.
* TPatchExitToShell - Subclass used to patch ExitToShell.
*
* Usage: To patch a trap create a subclass of TTrapPatch (see
* TPatchExitToShell for an example of how to do this).
* Once you have the subclass do something like this:
*
* static TPatchExitToShell sExitToShellPatch;
*
* #pragma segment Main
* #pragma profile off
* static pascal void OnExitToShell()
* {
* long OldA5 = SetCurrentA5(); // ***** Called from trap patches *****
*
* sExitToShellPatch.Remove(); // guaranteed not to fail
*
* DebugNewReportLeaks();
*
* sExitToShellPatch.CallRemoved();
*
* SetA5(OldA5);
* }
* #pragma profile reset
*
* sExitToShellPatch.Install(OnExitToShell);
*
* Note that for most traps you won't remove the patch
* in your replacement function.
*
* Change History (most recent first):
*
* <-> 1/13/96 JDJ Created (based on MacApp's class).
*/
#pragma once
#include <ZTypes.h>
typedef class TTrapPatch *TrapPatchPtr;
// ===================================================================================
// class TTrapPatch
// ===================================================================================
class TTrapPatch {
public:
TTrapPatch();
void PatchTrap(ushort theTrapNum, void* theRoutine);
// Patches the trap so that it calls routine.
void UnpatchTrap();
static void UnpatchAll();
UniversalProcPtr GetOldTrapAddr() const {return mOldTrapAddr;}
protected:
TrapPatchPtr GetPreviousPatchPtr() const;
TrapPatchPtr GetNewerPatchPtr() const;
protected:
ushort mTrapNum; // trap # being patched
UniversalProcPtr mOldTrapAddr; // old trap address
UniversalProcPtr mPatchRoutine; // new trap routine descriptor (created by subclasses
// of class TTrapPatch, cleaned up by TTrapPatch)
TrapPatchPtr mNextPatch; // next link in linked list of patches
static TrapPatchPtr msPatchList;
};
// ===================================================================================
// class TPatchExitToShell
// ===================================================================================
typedef pascal void (*ExitToShellType)(void);
class TPatchExitToShell : private TTrapPatch {
public:
TPatchExitToShell() {mRemovedTrapAddr = nil;}
void Install(ExitToShellType routine);
void Remove();
void CallRemoved();
bool Installed() {return mPatchRoutine != nil;}
private:
UniversalProcPtr mRemovedTrapAddr;
};